import request from "@/utils/request";
import {
  AddOrUpdateSkuParams,
  SkuList,
  SkuListResponse,
} from "./model/skuModel";

const enum Api {
  addOrUpdateSku = "/admin/product/saveSkuInfo",
  skuList = "/admin/product/findBySpuId",
  getSkuList = "/admin/product/list",
  onSale = "/admin/product/onSale",
  cancleSale = "/admin/product/cancelSale",
  getSkuInfo = "/admin/product/getSkuById",
  deleteSku = "/admin/product/deleteSku",
}

/**
 * 添加或修改SKU
 * @param data AddOrUpdateSkuParams
 * @returns null
 */
export const AddOrUpdateSkuApi = (data: AddOrUpdateSkuParams) => {
  return request.post<any, null>(Api.addOrUpdateSku, data);
};

/**
 * 获取SKU列表
 * @param spuId
 * @returns SkuList
 */
export const GetSkuListApi = (spuId: number) => {
  return request.get<any, SkuList>(Api.skuList + `/${spuId}`);
};

/**
 * 获取SKU列表
 * @param page
 * @param limit
 * @returns SkuListResponse
 */
export const GetSkuListApiResponse = (page: number, limit: number) => {
  return request.get<any, SkuListResponse>(
    Api.getSkuList + `/${page}/${limit}`
  );
};

/**
 * 上架
 * @param skuId
 * @returns null
 */
export const GetOnSaleApi = (skuId: number) => {
  return request.get<any, null>(Api.onSale + `/${skuId}`);
};

/**
 * 下架
 * @param skuId
 * @returns null
 */
export const GetCancleSaleApi = (skuId: number) => {
  return request.get<any, null>(Api.cancleSale + `/${skuId}`);
};

/**
 * 获取SKU信息
 * @param skuId
 * @returns AddOrUpdateSkuParams
 */
export const GetSkuInfoBySkuIdApi = (skuId: number) => {
  return request.get<any, AddOrUpdateSkuParams>(Api.getSkuInfo + `/${skuId}`);
};

/**
 * 删除SKU信息
 * @param skuId
 * @returns null
 */
export const DeleteSkuApi = (skuId: number) => {
  return request.delete<any, null>(Api.deleteSku + `/${skuId}`);
};
